package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.MyRecRecordBean;
import flc.ast.databinding.ActivityAnimalRecBinding;
import flc.ast.utils.AppSpUtils;
import stark.common.apis.base.ImgAnimalRet;
import stark.common.basic.event.EventStatProxy;

public class AnimalRecActivity extends BaseAc<ActivityAnimalRecBinding> {

    public static String imgPath;
    public static List<ImgAnimalRet> sAnimRets;
    private boolean isAvail = false;

    @Override
    protected int onCreate() {
        return R.layout.activity_animal_rec;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivAnimalRecBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivAvail.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivAvail:
                if (isAvail) {
                    isAvail = false;
                    mDataBinding.ivAvail.setImageResource(R.drawable.adianz);
                    mDataBinding.tvAvail.setTextColor(Color.parseColor("#D5D5D5"));
                } else {
                    isAvail = true;
                    mDataBinding.ivAvail.setImageResource(R.drawable.ayoubangzhu);
                    mDataBinding.tvAvail.setTextColor(Color.parseColor("#000000"));
                }
                break;
        }
    }

    @Override
    protected void initData() {
        Glide.with(mContext).load(imgPath).into(mDataBinding.ivResultImg);
        mDataBinding.tvResultName.setText(sAnimRets.get(0).name);
        mDataBinding.tvResultDesc.setText(sAnimRets.get(0).baike_info.description);
        int num = (int) (sAnimRets.get(0).score * 100);
        mDataBinding.tvResultSimilarity.setText(getString(R.string.similarity_num, num));
        mDataBinding.sbSimilarity.setProgress(num);
        saveRecord();
    }

    private void saveRecord() {
        List<MyRecRecordBean> listSave = new ArrayList<>();
        listSave.add(new MyRecRecordBean(imgPath, sAnimRets.get(0).name, "", sAnimRets.get(0).baike_info.description, TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd"))));
        List<MyRecRecordBean> listSp = AppSpUtils.getRecordList();
        if (listSp != null && listSp.size() > 0) {
            listSp.addAll(listSave);
            AppSpUtils.saveRecordList(listSp);
        } else {
            AppSpUtils.saveRecordList(listSave);
        }
    }

}